<? 
    session_start();
	include ("../core/conn.php");
	global $db;	
	$db = get_conn();
	
	$type = $_GET['t'];
	$due = $_GET['d'];
	$exp = $_GET['e'];	
	$id_location  = $_GET['l'];	
		
//ajax_comps/history.php?t=1&d=04/01/2011&e=04/21/2011
		
?>
<table width="100%" border="0">
  <tr>
    <td>Cobros Pendientes</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td><? 
			
		$sql = "select i.id_invoice, i.amount, i.due_date, i.exp_date, i.description, l.number, l.id_location, it.name, i.description
				from 
				`invoices` i , 
				`locations` l ,
				`invoices_type` it
				where 
				l.id_location =".$id_location." and
				i.id_location = l.id_location and
				i.id_it = it.id_it
				order by i.id_invoice";
			
		$result = mysql_query($sql);
			
		if($result){
				
			$data ="<table width='100%' border='0' align='left' >";
				
			if(mysql_num_rows($result) > 0){
					$data .="<tr>

						<td align='left' >
							ID
						</td>
						<td align='left' >
							Filial
						</td>							
						<td align='left' >
							Tipo
						</td>
						
						<td align='left' >
							Fecha Cobro
						</td>						
						
						<td align='left' >
							Fecha Pago
						</td>
						
						<td align='left' >
							Recibo
						</td>	
						<td align='left' >
							Comentarios
						</td>																								
						</tr>";					
				while($row = mysql_fetch_array($result)){
					//$owner_name = get_owner_name($row['id_location']);
					$data .="<tr>

						<td align='left' >
							".$row['id_invoice']."
						</td>						
						<td align='left' >
							".$row['number']." 
						</td>
						<td align='left' >
							".$row['name']."
						</td>													
						<td align='left' >
							".format_date($row['due_date'])."
						</td>
						<td align='left' >
							".format_date($row['exp_date'])."
						</td>
						<td align='center' >
							".format($row['amount'],2)."
						</td>	
						<td align='left' >
							".$row['description']."
						</td>																								
						</tr>";
						
						$total = $total + $row['amount'];
					
				}//while
				
					$data .="<tr>

						<td align='left' colspan='7'>
							<hr size='1'>
						</td>						
						</tr>";
										
					$data .="<tr>

						<td align='right' colspan='5'>
							Total
						</td>						
						<td align='center' >
							".format($total,2)."
						</td>	
						<td align='left' >
							&nbsp;
						</td>																								
						</tr>";
				
				
			}//if
				
			else{
					
				$data .= "<tr><td align='center'>No hay cobros pendientes</td></tr>";			
				
			}
				
			$data .="</table>";
			
		}else{
				
			error_handling($sql,mysql_error());
			
		}
			
		echo $data;
			
		?>
      &nbsp;</td>
  </tr>
</table>





	